import { inject, injectable, named } from "inversify";
import { CancellationToken, DebugConfiguration, WorkspaceFolder } from "vscode";
import { IMultiStepInput, IMultiStepInputFactory, InputStep } from "../../../common/utils/multiStepInput";
import { AttachRequestArguments, DebugConfigurationArguments, LaunchRequestArguments } from "../../types";
import { DebugConfigurationState, IDebugConfigurationService } from "../types";
import { IDebugConfigurationProviderFactory, IDebugConfigurationResolver } from "./types";

@injectable()
export class EQDebugConfigurationService implements IDebugConfigurationService {
    private cacheDebugConfig: DebugConfiguration | undefined = undefined;
    constructor(
        @inject(IDebugConfigurationResolver)
        @named('attach')
        private readonly attachResolver: IDebugConfigurationResolver<AttachRequestArguments>,
        @inject(IDebugConfigurationResolver)
        @named('launch')
        private readonly launchResolver: IDebugConfigurationResolver<LaunchRequestArguments>,
        @inject(IDebugConfigurationProviderFactory)
        private readonly providerFactory: IDebugConfigurationProviderFactory,
        @inject(IMultiStepInputFactory) private readonly multiStepFactory: IMultiStepInputFactory,
    ) { }

    public async provideDebugConfigurations(
        folder: WorkspaceFolder | undefined,
        token?: CancellationToken,
    ): Promise<DebugConfiguration[] | undefined> {
        const config: Partial<DebugConfigurationArguments> = {};
        const state = { config, folder, token };

        // Disabled until configuration issues are addressed by VS Code. See #4007
        const multiStep = this.multiStepFactory.create<DebugConfigurationState>();
        await multiStep.run((input, s) => this.pickDebugConfiguration(input, s), state);

        if (Object.keys(state.config).length === 0) {
            return;
        } else {
            return [state.config as DebugConfiguration];
        }
    }
    protected async pickDebugConfiguration(
        input: IMultiStepInput<DebugConfigurationState>,
        state: DebugConfigurationState,
    ): Promise<InputStep<DebugConfigurationState> | void> {
        console.log("here");
    }
}